//第三方类库加载管理js，方便切换lib
(function () {
    var r = new RegExp("(^|(.*?\\/))(include-lib\.js)(\\?|$)"),
      s = document.getElementsByTagName('script'), targetScript;
    for (var i = 0; i < s.length; i++) {
        var src = s[i].getAttribute('src');
        if (src) {
            // var m = src.match(r);
            var m = src.indexOf('include-lib') > -1;
            if (m) {
                targetScript = s[i];
                break;
            }
        }
    }

    //marsgis版本号,用于官网标题处版本号
    window.marsgis_version = "2.1.2"


    // cssExpr 用于判断资源是否是css
    var cssExpr = new RegExp('\\.css');

    function inputLibs(list) {
        if (list == null || list.length == 0) return;

        for (var i = 0, len = list.length; i < len; i++) {
            var url = list[i];
            if (cssExpr.test(url)) {
                var css = '<link rel="stylesheet" href="' + url + '">';
                document.writeln(css);
            } else {
                var script = '<script type="text/javascript" src="' + url + '"><' + '/script>';
                document.writeln(script);
            }
        }
    }

    //加载类库资源文件
    function load() {
        var arrInclude = (targetScript.getAttribute('include') || "").split(",");
        var libpath = (targetScript.getAttribute('libpath') || "");

        if (libpath.lastIndexOf('/') != libpath.length - 1)
            libpath += "/";

        var libsConfig = {
            'jquery': [
                libpath + "jquery/jquery-2.1.4.min.js",
            ],

            'highlight': [
                libpath + "highlight/styles/foundation.css",
                libpath + "highlight/highlight.pack.js"
            ],
            'turf': [
                libpath + "turf/turf.min.js"
            ],
            'terraformer': [
                libpath + "terraformer/terraformer-1.0.9.min.js",
                libpath + "terraformer/terraformer-wkt-parser-1.2.0.min.js",
            ],
            'ammo': [
                libpath + "ammo/ammo.js"
            ],
            'kriging': [
                libpath + "kriging/kriging.min.js"
            ],
            "mars3d-visual": [//echarts与mapV支持插件
                libpath + "cesiumjs/plugins/visual/mars3d-visual.js"
            ],
            "mars3d-space": [//卫星插件
                libpath + "cesiumjs/plugins/space/mars3d-space.js"
            ],
            'mars3d': [//三维地球“主库”
                libpath + "cesiumjs/Cesium/Widgets/widgets.css", //cesium
                libpath + "cesiumjs/Cesium/Cesium.js",
                libpath + "cesiumjs/plugins/compatible/version.js", //cesium版本兼容处理

                libpath + "cesiumjs/mars3d/mars3d.css", //mars3d
                libpath + "cesiumjs/mars3d/mars3d.js",
                libpath + "cesiumjs/plugins/navigation/mars3d-navigation.css", //导航插件
                libpath + "cesiumjs/plugins/navigation/mars3d-navigation.js",
                '../config/marsUrl.js' //一些服务地址统一配置
            ],

        };



        for (var i in arrInclude) {
            var key = arrInclude[i];
            inputLibs(libsConfig[key]);
        }

    }

    load();
})();
